package redis

import (
	gredis "github.com/garyburd/redigo/redis"
)

//SET key value [EX seconds] [PX milliseconds] [NX|XX]
func (r *RedisPool) Set(key interface{}, value interface{}, args ...interface{}) (string, error) {
	var tmp []interface{}
	tmp = append(tmp, key, value)
	tmp = append(tmp, args...)
	return gredis.String(r.Do("SET", tmp...))
}

//SETEX key value
func (r *RedisPool) SetEX(key interface{}, seconds int64, value interface{}) (string, error) {
	return gredis.String(r.Do("SETEX", key, seconds, value))
}

//GET key
func (r *RedisPool) GetString(key interface{}) (string, error) {
	return gredis.String(r.Do("GET", key))
}
func (r *RedisPool) GetInt(key interface{}) (int, error) {
	return gredis.Int(r.Do("GET", key))
}
func (r *RedisPool) GetInt64(key interface{}) (int64, error) {
	return gredis.Int64(r.Do("GET", key))
}
func (r *RedisPool) GetFloat64(key interface{}) (float64, error) {
	return gredis.Float64(r.Do("GET", key))
}
func (r *RedisPool) GetBool(key interface{}) (bool, error) {
	return gredis.Bool(r.Do("GET", key))
}

//MGET key [key ...]
func (r *RedisPool) MGet(keys ...interface{}) ([]string, error) {
	return gredis.Strings(r.Do("MGET", keys...))
}

//MSET key value [key value ...]
func (r *RedisPool) MSet(key interface{}, value interface{}, args ...interface{}) ([]string, error) {
	var tmp []interface{}
	tmp = append(tmp, key, value)
	tmp = append(tmp, args...)
	return gredis.Strings(r.Do("MSET", tmp...))
}

//DECR key
func (r *RedisPool) Decr(key interface{}) (int, error) {
	return gredis.Int(r.Do("DECR", key))
}

//INCR key
func (r *RedisPool) Incr(key interface{}) (int, error) {
	return gredis.Int(r.Do("INCR", key))
}

//EXISTS key [key ...]
//Return value
/*
1 if the key exists.
0 if the key does not exist.
*/
func (r *RedisPool) Exists(keys ...interface{}) (bool, error) {
	return gredis.Bool(r.Do("EXISTS", keys...))
}

//DEL key [key ...]
func (r *RedisPool) Del(keys ...interface{}) (int, error) {
	return gredis.Int(r.Do("DEL", keys...))
}

//EXPIRE key seconds
func (r *RedisPool) Expire(key string, seconds int64) (int, error) {
	return gredis.Int(r.Do("EXPIRE", key, seconds))
}

//KEYS pattern
func (r *RedisPool) Keys(pattern string) ([]string, error) {
	return gredis.Strings(r.Do("KEYS", pattern))
}
